home *** CD-ROM | disk | FTP | other *** search
- 06601010101800
- 1
- 2#
- F0110030
- 9[........................................................]001
- ŴANIMATEDSPRITES€
-
- ByIanSmith
-
- There have been many articles relating to the use of Sprites onthe
- Archimedes.ThesehavecoveredtheuseofPLOT&ED,X,Ytodisplaya
- Spriteinitsdefinedcoloursatpoint(X,Y)andtheuseofaMaskto
- allowabackgroundtoappearthroughthe'unused'partsofasprite.
- TheyhavealsoshowntheuseofExclusiveORplottingusingGCOL11,0to
- allowthespritetobemovedoveranycolouredbackground.
-
- TheEORsolutiontothislastproblem,ofmovingamulti-colouredsprite
- overamulticolouredbackground,worksBUTunlessagreatdealof
- thoughtisgiventopaletteselectionthespriteDOESNOTretainits
- definedcolourduringmovement.
-
- Manygameswillrequirethefacilitytodefineaspriteinspecified
- colours,withamask,andtomoveitSTILLretainingthosecolours
- ratherthanthoseproducedbyEOR.
-
- AsolutionistousethestandardMove/Display/EraseinaloopBUTNOT
- touseEOR.ThefollowingAlgorithmdoesthis:
-
-
- 1 Definethesprite'MySprite'WITHaMASK(usingSEDITonthe
- WelcomeDisk).
-
- 2 Determinethesizeof'MySprite'.
- ThismaybeknownBUTaSYScalldoesitforyou.
-
- LOOP
-
- 3 Determinethepositionwhere'MySprite'istobeplotted.
-
- 4 GRABasprite'Temp'fromthescreenatthispositionthe
- samesizeas'MySprite'.
-
- 5 PLOT'MySprite'withthemask.
-
- 6 PLOTthegrabbedsprite'Temp'toERASE'Mysprite'.
-
- ENDLOOP
-
- Thefollowingprogramdemonstratesthis:
- €
- 10 REM > SpritePlot
- 20 REM Copyright Ian Smith
- 30 REM March 1989
- 40
- 50 REM An example program to show the use of sprites moving
- 60 REM across a multi coloured background by grabbing an area
- 70 REM of screen as a sprite and then using it to overwrite the
- 80 REM moving sprite.
- 90
- 100 MODE 15 : REM Works in others modes
- 110 T$="Temp" : REM Will be the sprite grabbed from screen
- 120 M$="MySprite" : REM A masked sprite created with SEDIT
- 130 *SLOAD !Sprites
- 140
- 150 SYS &2E,40,,T$ TO ,,,W,H : REM Find size of sprite to grab
- 160 : REM W)idth and H)eight
- 170 PROCDrawBackground : REM Draw a Multicoloured background
- 180 PROCTitle : REM and put titles on
- 190
- 200 REPEAT
- 210 REM ****** MOVE ******
- 220 MOUSE X,Y,B
- 230 SYS &2E,16,,T$,1,X,Y,X+W*2,Y+H*4 : REM Grab sprite from screen
- 240
- 250 OSCLI("SCHOOSE " + M$ ) : REM Select original sprite
- 260
- 270 REM ****** DISPLAY ******
- 280 GCOL 8,0 : REM Now plot it with its mask
- 290 PLOT &ED, X,Y : REM at the mouse position
- 300 PLOT &ED,900,800 : REM and display it in rectangle
- 310
- 320 WAIT:WAIT : REM Synchronise output
- 330
- 340 OSCLI("SCHOOSE " + T$) : REM Now plot the grabbed sprite
- 350
- 360 REM ****** ERASE ******
- 370 GCOL 0,0
- 380 PLOT &ED,X,Y : REM at the same place
- 390 PLOT &ED,1000,800 : REM and in its rectangle
- 400 UNTIL B=7 : REM 3 buttons terminates
- 410 END
- 420
- 430 DEF PROCDrawBackground
- 440 GCOL 3 : RECTANGLE FILL 0,0,300,300 : REM Just a couple of
- 450 GCOL 4 : RECTANGLE FILL 50,50,50,50 : REM rectangles and
- 460 GCOL 12: CIRCLE FILL 800,400,200 : REM circle
- 470 GCOL 5 : CIRCLE FILL 600,300,100
- 480 OSCLI("SCHOOSE " + M$)
- 490 PLOT &ED,75,90 : REM and the sprite
- 500 ENDPROC
- 510
- 520 DEF PROCTitle
- 530 GCOL 1
- 540 RECTANGLE 900-2,800-4,W*2+4,H*4+8 : REM Draw rectangles
- 550 RECTANGLE 1000-2,800-4,W*2+4,H*4+8 : REM in which sprires
- 560 PRINT TAB(53,2);"S P R I T E S" : REM are displayed
- 570 PRINT TAB(52,3);"original grabbed"
- 580 PRINT TAB(0,1);"SPRITE DEMONSTRATION : use mouse to move sprite"
- 590 ENDPROC
-
-
- €Commentsontheprogram:
-
- PROCDrawBackgoundsetsupabackgroundtomoveover.
- PROCTitleSimplyputsTextandacoupleofrectanglesonthescreen
-
- 150UsesaSYScalltofindtheWidthandHeightof'MySprite'
- Thisisneededsothattherightsize'Temp'canbegrabbed.
- (SeeProgrammersReferenceManualpp429,433)
- 230GrabsthespritefromthescreenusingaSYScall.
- Notethe*2and*4tocompensateforscreenMODE15
- You'llneedtochangethisforotherresolutionmodes.
-
- 250Selects'MySprite'
-
- 280SelectstheMaskPlotoptionGCOL8.
-
- 290PlotsthespriteattheMouseselectedpoint
-
- 300Plotsthespriteinarectangletoshowitsoriginalcolours.
-
- 340Selects'Temp'
-
- 380Plots'Temp'effectivelyerasing'MySprite'
-
- 390Plots'Temp'initsrectangle.
-
- Theeffectof390hasaninterestingside-effect.
- Whenyouruntheprogrammovethespriteovertherectangle!Seewhat
- happens!
-
- Theprogram'SpritePlot'andSpriteFile'!Sprites'areonthismonth's
- diskBUTyoucanusetheprogrambykeyingitinANDALSOCREATINGA
- MASKEDSPRITEINMODE15USINGSEDITSAVEDAS!SPRITES.
-
- TheprogramcanobviouslybemodifiedtoruninotherModes.
- TheflickerontheSpritecanberemovedbymodifyingtheprogramto
- plotONLYifthemousehasbeenmoved.
-
-